package main

import (
	"database/sql"
	_ "github.com/mattn/go-sqlite3"
	"log"
)

/*func main() {
	engine,_:=geeorm.NewEngine("sqlite3","gee.db")
	defer engine.Close()
	s:=engine.NewSession()
	s.Raw("DROP TABLE IF EXISTS User;").Exec()
	s.Raw("CREATE TABLE User(Name text);").Exec()
	s.Raw("CREATE TABLE User(Name text);").Exec()
	result,_:=s.Raw("INSERT INTO User(`Name`)values(?),(?)","Tom","Sam").Exec()
	count,_:=result.RowsAffected()
	fmt.Printf("Exec success %d affected\n",count)
}*/


//测试事务
func main(){
	db,_:=sql.Open("sqlite3","gee.db")
	defer db.Close()
	db.Exec("CREATE TABLE IF NOT EXISITS User(`Name` text);")
	tx,_:=db.Begin()
	_,err1:=tx.Exec("INSERT INTO User(`Name`) VALUES(?)","Tom")
	_,err2:=tx.Exec("INSERT INTO User(`Name`) VALUES(?)","Jack")
	if err1!=nil||err2!=nil{
		tx.Rollback()
		log.Println("Rollback",err1,err2)
	}else{
		tx.Commit()
		log.Println("Commit")
	}
}